

import openai, os

openai.api_key = os.environ.get("OPENAI_API_KEY")

from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import LLMChain

llm = OpenAI(model_name="text-davinci-003", max_tokens=2048, temperature=0.5)


multiply_by_python_prompt = PromptTemplate(template="请写一段Python代码,通过调用jwt库,根据{payload}和{secret}生成jwt token", input_variables=["payload","secret"])
math_chain = LLMChain(llm=llm, prompt=multiply_by_python_prompt, output_key="answer")
answer_code = math_chain.run({"payload": "{\"tenant_code\": \"hwtest\",\"account\": \"hwtest\",\"redirect\": \"/\"}","secret":"******"})

from langchain.utilities import PythonREPL
python_repl = PythonREPL()
result = python_repl.run(answer_code)
print(result)